<include file="Manager:leftmenu" />
<style>
    .menus{
        padding:10px 10px;
        border:1px #ededed solid;
        margin-top:10px;
    }
    .menus label{
        padding:5px;
    }
</style>
<div class="content-right fl">

    <h1 class="content-right-title">添加/编辑管理员</h1>

    <form action="" id="form" method="POST">

        <div class="formitems">  
            <label class="fi-name"><span class="colorRed">*</span>管理员账号：</label>
            <div class="form-controls">
                <input type="text" class="input xlarge" name="username" value="<?php echo $minfo['username'];?>" <?php echo $minfo['username'] ? "readonly":"";?>>
                       <span class="fi-help-text">请输入管理员账号</span>
            </div>
        </div>

        <!--		<div class="formitems">  
                                <label class="fi-name"><span class="colorRed">*</span>管理员角色：</label>
                                <div class="form-controls">
                                        <select name="role_id" class="select  new">
                            <option value="-1">选择角色</option>
                            <?php foreach($datalist as $k=>$v){?>
                            <option value="<?php echo $v['role_id'];?>"   <?php echo ($v['role_id']==$minfo['role_id'])? "selected":"";?>><?php echo $v['role_name'];?></option>
                                                <?php } ?>
                            
                        </select>
                                        
                                        
                                        <span class="fi-help-text">管理员角色</span>
                                </div>
                        </div>-->

        <div class="formitems">
            <label class="fi-name">不可修改数据：</label>
            <div class="form-controls">
                <div class="radio-group">
                    <label><input type="radio" class="is_free_logistics" value="1" name="only_read" <?php echo isset($minfo['only_read']) && ($minfo['only_read']) ? "checked" : (!isset($minfo['only_read']) ? "checked":"");?>>不可修改</label>
                    <label><input type="radio" class="is_free_logistics" value="0" name="only_read" <?php echo isset($minfo['only_read']) && (!$minfo['only_read']) ? "checked" : "";?>>可修改</label>
                </div>
                <span class="fi-help-text"></span>
            </div>
        </div>
        
        <div id="app" class="formitems">  
            <label class="fi-name"><span class="colorRed">*</span>管理员权限：</label>
            <div class="form-controls">
                <div>
                    <template v-for="(item,index) in menus">
                        <div class="menus">
                            <div style="border-bottom: 1px #ededed solid;padding-bottom: 10px;">
                                {{item.menu.title}}：
                                <label style="display:none;"><input :value="item.menu.id" name="menu[]" type="checkbox" v-model="hasChild(index)"/>{{item.menu.title}}</label>
                                <label @click="selectAll(index)">
                                    <input type="checkbox" style="vertical-align:middle;"  v-model="item.menu.all" />
                                    <span>全选</span>
                                </label>
                            </div>
                            
                            <div v-if="pageList(index).length>0" style="padding:10px 0px;">
                                <span>页面：</span><br>
                                <template v-for="(citem,cindex) in pageList(index)">
                                    <label style='display:none;' v-if="citem.is_default==1"><input  style="vertical-align:middle;"  type="checkbox" name="submenu[]" :value="citem.id" v-model="hasChild(index)"/>{{citem.title}}</label>
                                    <label><input  style="vertical-align:middle;"  type="checkbox" name="submenu[]" :value="citem.id" v-model="citem.checked"/>{{citem.title}}</label>
                                </template>
                            </div>
                            
                            <div v-if="actionList(index).length>0" style="padding:10px 0px;">
                                <span>操作：</span><br>
                                <template v-for="(citem,cindex) in actionList(index)">
                                    <label v-if="citem.is_default==1"><input  style="vertical-align:middle;"  type="checkbox" name="submenu[]" :value="citem.id" v-model="hasChild(index)"/>{{citem.title}}</label>
                                    <label v-if="citem.is_default!=1"><input  style="vertical-align:middle;"  type="checkbox" name="submenu[]" :value="citem.id" v-model="citem.checked"/>{{citem.title}}</label>
                                </template>
                            </div>
                            
                        </div>
                    </template>
                </div>
                <span class="fi-help-text"></span>
            </div>
        </div>
        
        <div class="formitems">  
            <label class="fi-name"><span class="colorRed">*</span>管理员密码：</label>
            <div class="form-controls">
                <input type="text" class="input xlarge" name="password" value="" >
                <span class="fi-help-text">管理员密码 <?php if($minfo['username']){?>(编辑时,不填写则不更改)<?php } ?></span>
            </div>
        </div>

        <div class="formitems">  
            <label class="fi-name">管理员商城ID：</label>
            <div class="form-controls">
                <input type="text" class="input xlarge" name="uid" value="<?php echo $minfo['uid'];?>">
                <span class="fi-help-text">请填写管理员在商城的用户ID,用于手机端管理等</span>
            </div>
        </div>


        <div class="mgl120">
            <a href="javascript:AjaxFormSubmit();" class="btn btn-primary j-add">保 存</a>
        </div>
    </form>

</div>
<script src="//cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            menus: JSON.parse('<?=$menus?>'),
            msg: 'sdsd',
            sub_id: ''
        },
        created: function () {
            console.log(this.menus);
        },
        methods: {
            selectAll: function (index){
                var val = this.menus[index].menu.all;
                for(var i=0;i<this.menus[index].submenu.length;i++) {
                    this.menus[index].submenu[i].checked = val;
                }
            },
            hasChild: function (index){
                for(var i=0;i<this.menus[index].submenu.length;i++) {
                    if(this.menus[index].submenu[i].checked){
                        return true;
                    }
                }
                return false;
            },
            pageList: function (index) {
                var list  = [];
                for(var i=0;i<this.menus[index].submenu.length;i++) {
                    if(this.menus[index].submenu[i].level!=4){
                        list.push(this.menus[index].submenu[i]);
                    }
                }
                return list;
            },
            actionList: function (index) {
                var list  = [];
                for(var i=0;i<this.menus[index].submenu.length;i++) {
                    if(this.menus[index].submenu[i].level==4){
                        list.push(this.menus[index].submenu[i]);
                    }
                }
                return list;
            }
         }
    })
</script>